/**
 * related to list.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-07-15
 */
var page = sm("do_Page");
var app = sm("do_App");
var hashdata = mm("do_HashData");
var rootview = ui("$");
var nf = sm("do_Notification");
var common = require("common");
var pubUrl = require("url/pub");
var qqHttp = require("helper/http");
var listview = ui("listview");
var listdata = mm("do_ListData");
listview.bindItems(listdata);
var noData = [{"template":1,"labelContent":"还没有评价哦"}];
var params={};
var pageNum = 1;
var totalPages = 1;
var productId = 0,shopId=0;
//刷新数据
function refreshAllData(productId,shopId){
	pageNum = 1;
	if(shopId == 1){
		params.type = 2;//评价类型-商城	
	}else{
		params.type = 6;//评价类型-圈商
	}
	params.obj = 1;//评价对象-商品
	params.productId = productId
	params.page = pageNum;
	qqHttp.post(pubUrl.url.feedback.page, params, function(data) {
		totalPages = data.totalPages;
		listview.rebound();
		listdata.removeAll();
		if (data.page.content.length) {
			img_domain = data.page.content[0].fileDomain;
			listdata.addData(data.page.content);
		}else{
			listdata.addData(noData);
		}
		listview.refreshItems();
	})
}
page.on("productComment",function(data){
	productId = data.productId;
	shopId = data.shopId;
	refreshAllData(productId,shopId);
});
//下拉列表，刷新数据
listview.on("pull", function(data) {
	if (data.state == 2) {
		refreshAllData(productId,shopId);
		listview.rebound();//复位【一定要做】
	}
});

//上拉列表，翻页数据
listview.on("push", function(data) {
	if (data.state == 2) {
		getNextPageData();
		listview.rebound();//复位【一定要做】
	}
});

function getNextPageData(){
	pageNum++;
	if(totalPages >= pageNum){
	    params.page = pageNum;
	    qqHttp.post(pubUrl.url.feedback.page, params, function(data) {
			if (data.page.content.length) {
				listview.rebound();
				img_domain = data.page.content[0].fileDomain;
				listdata.addData(data.page.content);
			}
			listview.refreshItems();
		});
	}else {
		nf.toast("已是最后一页");
		listview.rebound();
		listview.refreshItems();
	}
}